/*!
 * Copyright (C) 2020 - All Rights Reserved by
 * @author : ZhaoYanbo
 * @email  : zyb920@hotmail.com
 * @created: 2020-10-31
 * @version: 1.0.0.0
 *
 */

#ifndef THUMBDATAMODEL_H
#define THUMBDATAMODEL_H

#include <QAbstractListModel>

class ThumbDataModel : public QAbstractListModel
{
    Q_OBJECT
public:
    enum DataRoles {
        PathRole = Qt::UserRole + 1,
        NameRole
    };
    explicit ThumbDataModel(QObject *parent = nullptr);
    ~ThumbDataModel()override;

    Q_INVOKABLE void setSource(const QStringList &list);

    Q_INVOKABLE bool insert(int index, const QString &path);
    Q_INVOKABLE bool append(const QString &path);
    bool append(const QStringList &list);

    Q_INVOKABLE bool remove(int index);
    Q_INVOKABLE int remove(const QString &path);

    Q_INVOKABLE void clear();
    Q_INVOKABLE int length() const;

    Q_INVOKABLE bool isValid(int index) const;

    Q_INVOKABLE QString filePath(int index) const;
    QString fileName(int index) const;
    QString fileName(const QString &file_path) const;

public:
    bool setData(const QModelIndex &index, const QVariant &value, int role) override;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

    int rowCount(const QModelIndex & parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &/*parent*/) const override;

protected:
    QHash<int, QByteArray> roleNames() const override;

private:
    QStringList m_headers;
    QStringList m_list;
    QHash<int, QByteArray> m_hRoleNames;
};

#endif // THUMBDATAMODEL_H
